//
// Created by wyh on 2025-06-14 22:36.
//

#ifndef TEST_UTILITY_INIFILE_H
#define TEST_UTILITY_INIFILE_H

#include <map>
#include <string>
#include "utility/value.h"

namespace wyh {
    namespace utility {
        class IniFile
        {
            typedef std::map<std::string,Value> Section;
        public:
            IniFile() = default;

            explicit IniFile(const std::string &filename);

            ~IniFile() = default;

            bool load(const std::string &filename);

            std::string str() const;

            void show() const;

            Value &get(const std::string &section, const std::string &key);

            void set(const std::string &section, const std::string &key, const Value &value);

            Section &operator[](const std::string &section)
            {
                return m_sections[section];
            }

            bool has(const std::string &section);

            bool has(const std::string &section, const std::string &key);

            void remove(const std::string &section);

            void remove(const std::string &section, const std::string &key);

            void clear();

            void save(const std::string &filename);

        private:
            std::string trim(std::string s);

        private:
            std::string m_filename;
            std::map<std::string,Section> m_sections;
        };
    } // namespace utility
} // namespace wyh


#endif //TEST_UTILITY_INIFILE_H
